package com.api.organization.adduser;

import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.VoidContextLoader;
import com.zyncro.api.IOrganizationApiService;
import com.zyncro.api.exceptions.ZyncroApiException;

@ContextConfiguration(loader = VoidContextLoader.class)
public class AddManyUsers extends AbstractApiTest {

	private static final long STORAGE_2MB = 2097152;

	private String userId;
	private String userPassword;

	private static long userNumber = 0;

	@BeforeClass
	public void setUpVariables() {

		this.userId = "";
		this.userPassword = "";

		AddManyUsers.userNumber = 0;

		getApi().login(userId, userPassword);
	}

	@Test(invocationCount = 1)
	public synchronized void testAddUser() throws ZyncroApiException {

		String name = "dev";
		String password = "123456";
		long storage = STORAGE_2MB;
		boolean canPublishCorporateFeed = false;
		boolean canCreateGroups = true;
		boolean canCreateDepartments = false;
		boolean isAdministrator = false;

		String lastname = "user" + userNumber;
		String email = name + lastname + "@yopmail.com";

		try {
			IOrganizationApiService org = getApi().getService(IOrganizationApiService.class);
			String result = org.addUser(name, lastname, email, password, storage, canPublishCorporateFeed, canCreateGroups,
					canCreateDepartments, isAdministrator, null, null);
			logger.info(result);
		} catch (Exception e) {
			logger.warn(e);
		}
		userNumber++;

		logger.info("User added email '" + email);
	}
}
